package com.example.sale1.user;

import com.example.sale1.dto.UserQuery;
import com.example.sale1.mybatis.entity.User;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigInteger;
import java.util.List;

@RestController
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/user/insertUser")
    public int insertUser(@RequestBody User user) {
        return userService.insertUser(user);
    }

    @PostMapping("/user/selectUserById")
    public User selectUserById(BigInteger userId) {
        return userService.selectUserById(userId);
    }

    @PostMapping("/user/selectUserByUsername")
    public User selectUserByUsername(String username) {
        return userService.selectUserByUsername(username);
    }

    @PostMapping("/user/selectUserByEmail")
    public User selectUserByEmail(String email) {
        return userService.selectUserByEmail(email);
    }

    @PostMapping("/user/selectUsers")
    public List<User> selectUsers(@RequestBody User user) {
        return userService.selectUsers(user);
    }

    @PostMapping("/user/selectUsersByPage")
    public PageInfo<User> selectUsersByPage(@RequestBody UserQuery query) {
        return userService.selectUsersByPage(query);
    }

    @PostMapping("/user/updateUser")
    public int updateUser(@RequestBody User user) {
        return userService.updateUser(user);
    }

    @PostMapping("/user/deleteUserById")
    public int deleteUserById(BigInteger userId) {
        System.out.println("userId="+userId);
        return userService.deleteUserById(userId);
    }


}
